package im.yisme.view.ui;

import im.yisme.R;
import im.yisme.view.ui.util.YViewThread;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.SurfaceHolder;

public class RecordResultView extends YView{

	private Bitmap uploadBmp, againBmp, tolyricsBmp, backBmp;
	private Bitmap countBmp, lengthBmp, titleBmp;
	private int noteNum;
	private String duration;
	
	public RecordResultView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		init();
	}

	private void init(){
		initData();
		initBitmap();
	}
	private void initData(){
		noteNum = 0;
		duration = "";
	}
	public void setData(int noteNum, String duration){
		this.noteNum = noteNum;
		this.duration = duration;
	}
	@Override
	protected void createThread() {
		// TODO Auto-generated method stub
		paintThread = new RecordResultPaintThread(holder);
	}
	
	private void initBitmap() {
		// TODO Auto-generated method stub
		uploadBmp = BitmapFactory.decodeResource(getResources(), R.drawable.record_result_upload);
		againBmp = BitmapFactory.decodeResource(getResources(), R.drawable.record_result_again);
		tolyricsBmp = BitmapFactory.decodeResource(getResources(), R.drawable.record_result_tolyrics);
		backBmp = BitmapFactory.decodeResource(getResources(), R.drawable.back);
		countBmp = BitmapFactory.decodeResource(getResources(), R.drawable.result_count);
		lengthBmp = BitmapFactory.decodeResource(getResources(), R.drawable.record_length);
		titleBmp = BitmapFactory.decodeResource(getResources(), R.drawable.record_result_title);
	}

	class RecordResultPaintThread extends YViewThread{

		public RecordResultPaintThread(SurfaceHolder holder) {
			super(holder);
			// TODO Auto-generated constructor stub
		}

		@Override
		protected void paint(Canvas canvas) {
			// TODO Auto-generated method stub
			canvas.drawColor(Color.WHITE);
			
			Paint paint = new Paint();
			paint.setStrokeWidth(1);
			paint.setAntiAlias(true);
			
			Resources r = getResources(); 
			float title_x = r.getDimension(R.dimen.record_result_title_x);
			float title_y = r.getDimension(R.dimen.record_result_title_y);
			float count_x = r.getDimension(R.dimen.record_result_count_x);
			float count_y = r.getDimension(R.dimen.record_result_count_y);
			float length_x = r.getDimension(R.dimen.record_result_length_x);
			float length_y = r.getDimension(R.dimen.record_result_length_y);
			float upload_x = r.getDimension(R.dimen.record_result_upload_x);
			float upload_y = r.getDimension(R.dimen.record_result_upload_y);
			float again_x = r.getDimension(R.dimen.record_result_again_x);
			float again_y = r.getDimension(R.dimen.record_result_again_y);
			float tolyrics_x = r.getDimension(R.dimen.record_result_tolyrics_x);
			float tolyrics_y = r.getDimension(R.dimen.record_result_tolyrics_y);
			float back_x = r.getDimension(R.dimen.record_result_back_x);
			float back_y = r.getDimension(R.dimen.record_result_back_y);
			
			canvas.drawBitmap(titleBmp, title_x, title_y, paint);
			canvas.drawBitmap(countBmp, count_x, count_y, paint);
			canvas.drawBitmap(lengthBmp, length_x, length_y, paint);
			canvas.drawBitmap(uploadBmp, upload_x, upload_y, paint);
			canvas.drawBitmap(againBmp, again_x, again_y, paint);
			canvas.drawBitmap(tolyricsBmp, tolyrics_x, tolyrics_y, paint);
			canvas.drawBitmap(backBmp, back_x, back_y, paint);
			
			
			paint.setTextSize(30);
			canvas.drawText(noteNum+"", 250, 235, paint);
			canvas.drawText(duration, 560, 220, paint);
		}
		
	}
}
